home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / plane / d2_dic_old.c next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.4 KB  |  108 lines

  1. #include "LEDA/d2_dictionary.h"
  2.  
  3.  
  4.  
  5.  
  6. main()
  7. {
  8.  
  9.   d2_dictionary<double,double,string> S;
  10.  
  11.   list<dic2_item> L;
  12.   dic2_item       it;
  13.   char            ch;
  14.   double          x,y;
  15.  
  16.  
  17.  
  18.   while (ch != 'q')
  19.   { 
  20.     cout << "(r/s/f/i/d/D/l/q): ";
  21.     cin  >> ch;
  22.  
  23.     float T  = used_time();
  24.      
  25.     switch(ch) {
  26.  
  27.     case 'i': { cout << "insert point: ";
  28.                 cin >> x >> y;
  29.                 S.insert(x,y,string("x = %f",x));
  30.                 break;
  31.                }
  32.  
  33.     case 'r': { init_random();
  34.                 int n = read_int("#random points = ");
  35.                 while (n--)
  36.                 { double x = random(1,1000)/100.0;
  37.                   double y = random(1,1000)/100.0;
  38.                   S.insert(x,y,string("x = %f",x));
  39.                  }
  40.                 cout << string("time: %6.2f\n",used_time(T));
  41.                 break;
  42.                }
  43.  
  44.     case 's': { double a=read_real("x0=");
  45.                 double b=read_real("x1=");
  46.                 double c=read_real("y0=");
  47.                 double d=read_real("y1=");
  48.   
  49.                 L = S.range_search(a,b,c,d);
  50.   
  51.                 forall(it,L) cout << S.key1(it) << " " << S.key2(it) << "\n";
  52.                 newline;
  53.               
  54.                 cout << string("time: %6.2f\n",used_time(T));
  55.                 break;
  56.               }
  57.  
  58.  
  59.     case 'd': { cout << "delete point: ";
  60.             cin >> x >> y;
  61.                 S.del(x,y);
  62.                 break;
  63.                }
  64.  
  65.     case 'D': { double a=read_real("x0=");
  66.                 double b=read_real("x1=");
  67.                 double c=read_real("y0=");
  68.                 double d=read_real("y1=");
  69.   
  70.                 L = S.range_search(a,b,c,d);
  71.   
  72.                 forall(it,L) 
  73.                 { x = S.key1(it);
  74.                   y = S.key2(it);
  75.                   cout << "delete: " << x  << " " << y <<"\n";
  76.                   S.del(x,y);
  77.                  }
  78.                 newline;
  79.               
  80.                 cout << string("time: %6.2f\n",used_time(T));
  81.                 break;
  82.               }
  83.  
  84.  
  85.     case 'f': { cout << "find point: ";
  86.             cin >> x >> y;
  87.                 if (S.lookup(x,y) != nil) cout << "yes";
  88.                 else cout << "no";
  89.                 newline;
  90.                 break;
  91.                }
  92.  
  93.  
  94.     case 'l': { L = S.all_items();
  95.                 forall(it,L) 
  96.                   cout << S.key1(it) << " " << S.key2(it) << "\n";
  97.                 newline;
  98.                 break;
  99.                }
  100.  
  101.  
  102.     } //switch
  103.  
  104.   } //for
  105.  
  106.   return 0;
  107. }
  108.